import os, base64
import torque.settings as settings

def getLocalFiles(path):
    file_list = []
    path.replace('..','')
    path = settings.TORQUE['base_path'] + path
    for node in os.listdir(path):
	node = node
        node_path = path + node
	if node == 'sam':
		if isinstance(node_path,str):
			raise NameError(node_path)
        if node[0] == '.': continue;
        if os.path.isfile(path + node): 
            file_list.append({
                'name': node,
                'path': node_path.replace(settings.TORQUE['base_path'],''),
                'extension': node[node.rfind('.')+1:],
                'base64': base64.urlsafe_b64encode(node_path.replace(settings.TORQUE['base_path'],'')),
                'type':'file',
                'size': os.path.getsize(node_path)
            })
        elif os.path.isdir(path + node):
            file_list.append({
                'name': node,
                'path': node_path.replace(settings.TORQUE['base_path'],''),
                'base64': base64.urlsafe_b64encode(node_path.replace(settings.TORQUE['base_path'],'')+'/'),
                'extension': 'folder',
                'type': 'folder',
                'size': -1,
            })

    return file_list
